package com.workerhelping.controller;

import com.workerhelping.feignClients.MySQLFeignClient;
import com.workerhelping.result.Result;
import com.workerhelping.result.ResultCodeEnum;
import com.workerhelping.vo.AnalyzeRecordMoneyVO;
import com.workerhelping.vo.AnalyzeYearAndMoneyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/analyze")
public class AnalyzeController {

    @Autowired
    private MySQLFeignClient mySQLFeignClient;

    /**
     * 数据分析
     * - 每年对应的发放金额
     * @return
     */
    @GetMapping("/getYearAndMoney")
    public Result<List<AnalyzeYearAndMoneyVO>> getYearAndMoney() {
        Result<List<AnalyzeYearAndMoneyVO>> getResult =  mySQLFeignClient.getYearAndMoney();
        if (!getResult.isOk())
            return Result.build(null, ResultCodeEnum.DATA_IS_EMPTY);
        List<AnalyzeYearAndMoneyVO> analyzeYearAndMoneyVOS = getResult.getData();
        return Result.ok(analyzeYearAndMoneyVOS);
    }

    /**
     * 数据分析
     * - 每个档案对应的发放金额
     * @return
     */
    @GetMapping("/getRecordMoney")
    public Result<List<AnalyzeRecordMoneyVO>> getRecordMoney() {
        Result<List<AnalyzeRecordMoneyVO>> getResult =  mySQLFeignClient.getRecordAndMoney();
        if (!getResult.isOk())
            return Result.build(null, ResultCodeEnum.DATA_IS_EMPTY);
        List<AnalyzeRecordMoneyVO> analyzeRecordMoneyVOS = getResult.getData();
        return Result.ok(analyzeRecordMoneyVOS);
    }
}
